package com.study.threadPackage;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class ThreadDownLoad extends Thread{
    private String url;
    private String name;

    public ThreadDownLoad(String url, String name) {
        this.url = url;
        this.name = name;
    }

    public ThreadDownLoad (){}
    @Override
    public void run() {
        webDownLoad downLoad = new webDownLoad();
        downLoad.downLoadImg(url,name);
        System.out.println("下载成功:"+name);
    }

    public static void main(String[] args) {
        ThreadDownLoad load = new ThreadDownLoad("https://bkimg.cdn.bcebos.com/pic/d043ad4bd11373f082022223f9445cfbfbedab64ae7e?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", "李.jpg");
        ThreadDownLoad load1 = new ThreadDownLoad("https://bkimg.cdn.bcebos.com/pic/d043ad4bd11373f082022223f9445cfbfbedab64ae7e?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", "浩.jpg");
        ThreadDownLoad load2 = new ThreadDownLoad("https://bkimg.cdn.bcebos.com/pic/5d6034a85edf8db1cb133d2e1868ca54564e9258de6c?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5/format,f_auto", "存.jpg");
        load.start();
        load1.start();
        load2.start();
    }
}

// 使用io 进行图片的下载
class webDownLoad{
  public void downLoadImg (String url,String name) {
      try {
          FileUtils.copyURLToFile(new URL(url),new File(name));
      } catch (IOException e) {
          e.printStackTrace();
          System.out.println("io 异常 downLoadImg出现错误");
      }
  }
}